package initialize

import (
	"errors"
	"github.com/olivere/elastic/v7"
	"log"
	"os"
	"shop/goods-srv/global"
	"time"
)

func InitEs() {
	host := "http://192.168.31.226:9200"
	var err error
	global.EsClient, err = elastic.NewClient(
		elastic.SetURL(host),
		elastic.SetSniff(false),
		elastic.SetGzip(true),
		elastic.SetHealthcheck(true),
		elastic.SetHealthcheckTimeout(10*time.Second),
		elastic.SetErrorLog(log.New(os.Stderr, "ELASTIC", log.LstdFlags)), // 设置日志输出的名字
		elastic.SetInfoLog(log.New(os.Stdout, "", log.LstdFlags)),         // 输出日志级别
	)
	if err != nil {
		err = errors.New("连接es失败")
	}

}
